/**
 * 简单封装方式 （get/post/put/delete）
 */

//导入封装的自定义配置的axios、配置的config
import {service} from "./axios"; // 已经promise化
import {config} from '../config/config.js'
const baseUrl = process.env.NODE_ENV === 'development' ? config.base_url.dev : config.base_url.pro;
config.api_base_url = baseUrl;
//封装get请求
export function get(url, params = {}) {
    params.t = new Date().getTime(); //get方法加一个时间参数,解决ie下可能缓存问题.
    return service({
        url: config.api_base_url+url,
        method: 'get',
        headers: {},
        params
    })
}
//封装post请求
export function post(url, data = {}) {
    return service({
        url: config.api_base_url+url,
        method: 'post',
        headers: {
            'Content-Type':'application/json;charset=UTF-8'
        },
        data:JSON.stringify(data)
    })
}

//封装put方法 (restfulAPI常用)
export function put(url,data = {}){
    return service({
        url: config.api_base_url+url,
        method: 'put',
        headers: {
            'Content-Type':'application/json;charset=UTF-8'
        },
        data:JSON.stringify(data)
    })
}

//删除方法(restfulAPI常用)
export function deletes(url){
    return service({
        url: config.api_base_url+url,
        method: 'delete',
        headers: {}
    })
}
